package com.qyc.Microservice.dto.pojo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import com.fasterxml.jackson.annotation.JsonView;
import com.qyc.Microservice.dto.constant.ValidatorConstant;
import com.qyc.Microservice.dto.validatedgroup.ValidatedGroup;

import io.swagger.annotations.ApiModel;
import lombok.Data;

@Entity
@Table(name="user")
@Data
@ApiModel(description = "用户信息")
public class User {
	
	/**
	 * 定义不同的视图
	 * 
	 * @author qiaosl
	 *
	 */
	public interface UserId{};
	
	public interface NameAndAgeView extends UserId{};
	
	public interface SimpleView extends NameAndAgeView{};
	
	public interface DetailView extends SimpleView{};
	
	@JsonView(UserId.class)
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@NotNull(message = "{user.id.NotNull}",groups = {ValidatedGroup.Delete.class,ValidatedGroup.Update.class})
	private Integer id;
	
	@JsonView(NameAndAgeView.class)
	@NotNull(message = "{user.name.NotNull}",groups = {ValidatedGroup.Select.class,ValidatedGroup.Save.class})
	@Column(name="name")
	private String name;
	
	@JsonView(NameAndAgeView.class)
	@Min(value = 0,message = "{user.age.Min}",groups = {ValidatedGroup.Save.class})
	@Max(value = 200,message = "{user.age.Max}",groups = {ValidatedGroup.Save.class})
	@Column(name="age")
	private Integer age;
	
	@JsonView(DetailView.class)
	@NotNull(message = "{user.password.NotNull}",groups = {ValidatedGroup.Select.class,ValidatedGroup.Save.class})
	@Size(min = 6,max = 20,message = "{user.password.Size}",groups = {ValidatedGroup.Select.class,ValidatedGroup.Save.class})
	@Pattern(regexp = ValidatorConstant.PASSWORD,message = "{user.password.Pattern}",groups = {ValidatedGroup.Select.class,ValidatedGroup.Save.class})
	@Column(name="password")
	private String password;
	
	@JsonView(SimpleView.class)
	@Column(name="sex")
	@NotNull(message = "{user.sex.NotNull}",groups = {ValidatedGroup.Save.class})
	private Integer sex;
}
